// calculate its cosine
double result = Math.cos( Math.toRadians(degrees) );
One function is nested inside another:
double result = Math.cos( Math.toRadians(degrees) );
This is perfectly fine, and is a reasonable way to write the code,
as long as the inner function returns a value that is correct for the outer function.
In fact, you could nest the function calls within println()
:
// calculate its cosine and print the result System.out.println("cosine: " + Math.cos( Math.toRadians(degrees) ) );
It is a matter of taste, sometimes, how much put in one statement. Your goal should be to make the logic clear, not to save typing.
Which page in this chapter is your favorite?